[t:/]$ 지식_

간단한 이중 포인터, 포인터의 포인터 예제.

2011/05/30

간단한 이중 포인터 예제.

포인터를 다수 써야 하는 데,
이걸 포인터의 배열로 쓰기는 싫고..
힙에서 끌어오고 싶을 때는..

이중 포인터를 쓴다.

뭐 대부분은 굳이 몇 바이트까지 바득바득 쥐어짜는 것 보다는..
전역변수를 잡는 것이 성능에서 유리하지만..

소프트웨어 신뢰성도 그렇고 폼도 안 나니깐..


#include <stdio.h>
#include <stdlib.h>
#include <time.h>

main()
{
        int i;
        time_t tt;
        char **pp;
        char **temp;

        pp = (char **)malloc(30000 * sizeof(char *));

        srandom(time(&tt));

        temp = pp;

        for (i = 0; i < 30000; i++) {
// 셋 다 동치임을 이해할 수 있어야 함,
//              pp[i] = malloc(random() % 72);
//              *(pp + i) = malloc(random() % 72);
                *temp = malloc(random() % 72);
                temp++;
        }

        for (i = 0; i < 30000; i++) {
                free(pp[i]);  // 이렇게 해지해되 된다능.
        }
        free(pp);

}




공유하기













[t:/] is not "technology - root". dawnsea, rss